package com.qfedu.servlet;

import com.qfedu.entity.PageBean;
import com.qfedu.entity.Product;
import com.qfedu.service.IProductService;
import com.qfedu.service.impl.ProductService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/product")
public class ProductServlet extends BaseServlet {
    private IProductService productService = new ProductService();
    public void getPageBean(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String currentPage = request.getParameter("currentPage");
        String typeid = request.getParameter("id");
        PageBean pageBean = productService.getPageBean(Integer.parseInt(currentPage), Integer.parseInt(typeid));
        request.getSession().setAttribute("pageBean",pageBean);
        request.getSession().setAttribute("id",typeid);
        response.sendRedirect("goodsList.jsp");
    }

    public Product getProduct(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String id = request.getParameter("tid");
        Product product = productService.getProduct(Integer.parseInt(id));
        request.getSession().setAttribute("product",product);
        response.sendRedirect("goodsDetail.jsp");
        return product;
    }
}
